/**
 * Created by Sean Patrick Floyd (<a
 * href="mailto:sfloyd@mytoys.de">sfloyd@mytoys.de</a>) on 14.06.2010.
 */
package com.google.code.wicket.auth.component.value.provider.session;

import java.util.Collection;
import java.util.Collections;

import org.apache.wicket.Session;

import com.google.code.wicket.auth.component.value.provider.MultiValueProvider;

/**
 * A Provider for authentication and authorization based on a custom session
 * implementation. Override this and provide implementations for
 * {@link #isLoggedIn(Session)} and {@link #getPrivileges(Session)}.
 * 
 * @param <S>
 *            Session type
 * @param <T>
 *            Privilege type
 */
public abstract class SessionBasedMultiValueProvider<S extends Session, T>
        extends MultiValueProvider<T> implements
        SessionMultiAuthorizationProvider<S, T> {

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    public final Collection<T> getValues() {
        final S session = (S) Session.get();

        return this.isLoggedIn(session)

        ? Collections.<T> emptySet()

        : this.getPrivileges(session);
    }

}
